package com.zhj.springbootorderrabbitmqproducer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhj
 */
@Configuration
public class RabbitMqConfiguration {
    // 1. 声明fanout模式交换机
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanout_order_exchange",true,false);
    }
    // 2. 声明队列 sms email wechat
    @Bean
    public Queue smsQueue() {
        return new Queue("sms.fanout.queue",true);
    }
    @Bean
    public Queue emailQueue() {
        return new Queue("email.fanout.queue",true);
    }
    @Bean
    public Queue wechatQueue() {
        return new Queue("wechat.fanout.queue",true);
    }
    // 3. 完成绑定关系
    @Bean
    public Binding smsBinding() {
        return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
    }
    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
    }
    @Bean
    public Binding wechatBinding() {
        return BindingBuilder.bind(wechatQueue()).to(fanoutExchange());
    }

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct_order_exchange",true,false);
    }
    @Bean
    public Queue smsDirectQueue() {
        return new Queue("sms.direct.queue",true);
    }
    @Bean
    public Binding dSMSBinding() {
        return BindingBuilder.bind(smsDirectQueue()).to(directExchange()).with("sms.direct.key");
    }
}
